'use strict';

module.exports = function(grunt) {  
	require('load-grunt-tasks')(grunt);

	grunt.initConfig({
		pkg: grunt.file.readJSON('package.json'),
		banner: '/*! <%= pkg.name %>-<%= pkg.version %> */',
		connect: {
			options: {
				// hostname: '0.0.0.0',
				port: 9001
			},
			livereload: {
				options: {
					middleware: function (connect, options) {
						return [
							require('connect-livereload')(),
							connect.static(options.base[0]),
							connect.directory(options.base[0])
						];
					}
				}
			}
		},
		watch: {
			build: {
				files: [
					'sass/**/*.scss',
					'coffee/**/*.coffee'
				],
				tasks: ['build']
			},
			livereload: {
				options: {
					livereload: true,
				},
				files: [
					'{,*/}*.html',
					'css/**/*.css',
					'js/**/*.js'
				]
			}
		},
		sass: {
			options: {
				style: 'compact'
			},
			dist: {
				files: [{
					expand: true,
					cwd: 'sass',
					src: ['*.scss'],
					dest: 'css',
					ext: '.css'
				}]
			}
		},
		coffee: {
			dist: {
				files: [{
					expand: true,
					cwd: 'coffee',
					src: [
						'*.coffee'
					],
					dest: 'js',
					ext: '.js'
				}]
			}
		},
		autoprefixer: {
			options: {
				// diff: true,
				browsers: [
					'last 4 version',
					'> 1%'
				]
			},
			all: {
				files: [{
					expand: true,
					cwd: 'css',
					src: [
						'*.css'
					],
					dest: 'css',
					ext: '.css'
				}]
			}
		}
	});

	grunt.registerTask('server', [
		'build',
		'connect',
		'watch'
	]);

	grunt.registerTask('build', [
		'sass',
		'autoprefixer',
		'coffee'
	]);

	grunt.registerTask('default', [
		'server'
	]);

};